<?php
/**********************
**errors.inc
**Date Created: 4/13/2009
**Copyright 2009 Tomorrow Tech Industries
**Contact: RPITomorrowTech@gmail.com
**********************/

//Tomorrow Tech return type
//Return succeeded		

/****************************************
Success codes
****************************************/
#define TT_SUCCESS_DECLARE(x)	(x)
//Standard success case
define("TT_OK",	1);

//Succeeded, but something was suspicious
define("TT_WARNING", 2);

/****************************************
Failure codes
****************************************/
//Generic error
define("TT_GENERAL", -1);

//Out of memory of other memory error
define("TT_MEM", -2);

//Access denied or other permissions issues
define("TT_ACCESS", -3);

//A network resource is unavailable
define("TT_NETWORK", -4);
	
//An invalid input was detected
define("TT_INVALID_INPUT", -5);

//Unsupported Feature
define("TT_UNSUPPORTED", -6);

//Return true if succeeded, false otherwise
function TT_SUCCEEDED($x) 	
{
	return $x >= 0;
}

//Return true if failed, false otherwise
function TT_FAILED($x)
{
	return $x < 0;
}

function errorString($error)
{
	if( $error == TT_OK )
	{
		return "TT_OK";
	}
	if( $error == TT_WARNING )
	{
		return "TT_WARNING";
	}

	//Failure codes
	if( $error == TT_GENERAL )
	{
		return "TT_GENERAL";
	}
	if( $error == TT_MEM )
	{
		return "TT_MEM";
	}
	if( $error == TT_ACCESS )
	{
		return "TT_ACCESS";
	}
	if( $error == TT_NETWORK )
	{
		return "TT_NETWORK";
	}
	if( $error == TT_INVALID_INPUT )
	{
		return "TT_INVALID_INPUT";
	}
	if( $error == TT_UNSUPPORTED )
	{
		return "TT_UNSUPPORTED";
	}
}

//Test Errors:
function testErrors()
{
	$succeeded = true;

	echo "<H1>Error Testing: </H1>\n";
	
	if( TT_SUCCEEDED(TT_OK) )
	{
		echo "TT_SUCCEEDED: SUCCEEDED when should have.<BR>";
	}
	else
	{
		echo "<B> TT_SUCCEEDED: FAILED when shouldn't have.</B><BR>";
		$succeeded = false;
	}

	if( TT_SUCCEEDED(TT_INVALID_INPUT) )
	{
		echo "<B>TT_SUCCEEDED: true when shouldn't have.</B><BR>";
		$succeeded = false;
	}
	else
	{
		echo "TT_SUCCEEDED: false when should have.<BR>";
	}


	if( TT_FAILED(TT_OK) )
	{
		echo "<B>TT_FAILED: true when shouldn't have.</B><BR>";
		$succeeded = false;
	}
	else
	{
		echo "TT_FAILED: false when should have.<BR>";
	}

	if( TT_FAILED(TT_INVALID_INPUT) )
	{
		echo "TT_FAILED: true when should have.<BR>";
	}
	else
	{
		echo "TT_FAILED: false when shouldn't have.<BR>";
		$succeeded = false;
	}

	/*
	echo "<BR>TT_OK: " . TT_OK . "<BR>";
	echo "TT_WARNING: ". TT_WARNING . "<BR>";
	echo "TT_MEM: " . TT_MEM . "<BR>";
	echo "TT_ACCESS: " . TT_ACCESS . "<BR>";
	echo "TT_NETWORK: " . TT_NETWORK . "<BR>";
	echo "TT_INVALID_INPUT: " . TT_INVALID_INPUT . "<BR>";
	echo "TT_UNSUPPORTED: " . TT_UNSUPPORTED . "<BR>";
	*/
	
	return $succeeded;
}
?>
